/*
 * Copyright © 2024-2025 Wenze Wei
 *
 * This file is part of StadionOS.
 *
 * This Source Code Form is subject to the terms of the GNU General Public License, v. 2.0.
 * You can obtain a copy of the GPL at
 * https://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 */

#include "test.h"

void test_Smemchr() {
    const char *s = "Hello, World!";
    Sprint("String s: %s\n", s);
    Sprint("Length of s: %zu\n", Sstrlen(s));
    char *result = Smemchr(s, 'W', Sstrlen(s));
    Sprint("Result of Smemchr: %p, Expected: %p\n", (void*)result, (void*)(s + 7));
    assert(result == s + 7);

    result = Smemchr(s, 'x', Sstrlen(s));
    Sprint("Result of Smemchr for 'x': %p\n", (void*)result);
    assert(result == NULL);

    Sprint("Smemchr tests passed.\n");
}

void test_Smemcmp() {  
    const char *s1 = "Hello";  
    const char *s2 = "Hello";  
    const char *s3 = "Hellz";  

    assert(Smemcmp(s1, s2, 5) == 0);  
    assert(Smemcmp(s1, s3, 5) < 0);  
    
    Sprint("Smemcmp tests passed.\n");
}  

void test_Smemcpy() {  
    char dest[20];  
    Smemcpy(dest, "Hello", 6);
    assert(Sstrcmp(dest, "Hello") == 0);
    
    Sprint("Smemcpy tests passed.\n");
}  

void test_Sstrcat() {  
    char dest[20] = "Hello";  
    Sstrcat(dest, ", World!");  
    assert(Sstrcmp(dest, "Hello, World!") == 0);
    
    Sprint("Sstrcat tests passed.\n");
}  

void test_Sstrchr() {  
    const char *s = "Hello, World!";  
    char *result = Sstrchr(s, 'W');  
    assert(result == s + 7);  

    result = Sstrchr(s, 'x');  
    assert(result == NULL);  
    
    Sprint("Sstrchr tests passed.\n");
}  

void test_Sstrcmp() {  
    const char *s1 = "Hello";  
    const char *s2 = "Hello";  
    const char *s3 = "Hellz";  

    assert(Sstrcmp(s1, s2) == 0);  
    assert(Sstrcmp(s1, s3) < 0);  
    
    Sprint("Sstrcmp tests passed.\n");
}  

void test_Sstrlen() {  
    assert(Sstrlen("Hello") == 5);  
    assert(Sstrlen("") == 0);  
    
    Sprint("Sstrlen tests passed.\n");
}  

void test_Sctype() {
    char c = 'g';

    Sprint("isalpha(%c): %d\n", c, Sisalpha(c));
    Sprint("isdigit('%c'): %d\n", c, Sisdigit(c));
    Sprint("islower('%c'): %d\n", c, Sislower(c));
    Sprint("toupper('%c'): %c\n", c, Stoupper(c));
}
